package com.lance.answer.gui.answer.gk.answer;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.lance.answer.gui.answer.AnswerObject;
import com.lance.answer.gui.answer.Util;
import com.lance.answer.gui.answer.gk.DealInfoUtil;
import com.lance.answer.gui.answer.gk.answer.task.UploadFileTask;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingDeque;

@Slf4j
public class UploadFileTmp {

    /**
     * 进度表：
     * 6-18 19:55开始测试 公共行政学 行政管理专科
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        int sync = 15;
     //   Thread.sleep(1000*60*60*1);
       // Thread.sleep(1000*60*60*9);
        Map<String,List<String>> all = Maps.newHashMap();
        all.put("习近平新时代中国特色社会主义思想",Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=243281"));
        all.put("计算机应用基础",Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=244498"));
        all.put("Web开发基础",Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=222252","http://xinjiang.ouchn.cn/mod/assign/view.php?id=222253",
                "http://xinjiang.ouchn.cn/mod/assign/view.php?id=222254","http://xinjiang.ouchn.cn/mod/assign/view.php?id=222255","http://xinjiang.ouchn.cn/mod/assign/view.php?id=222256"));
        all.put("中国近现代史纲要",Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=242978"));
        all.put("可编程控制器应用",Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=230969","http://xinjiang.ouchn.cn/mod/assign/view.php?id=230970"));
        all.put("公共政策概论",Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=266218","http://xinjiang.ouchn.cn/mod/assign/view.php?id=266219","http://xinjiang.ouchn.cn/mod/assign/view.php?id=266220"));
        all.put("公共行政学",Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=268419"));
        all.put("西方经济学",Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=207972","http://xinjiang.ouchn.cn/mod/assign/view.php?id=207973",
        "http://xinjiang.ouchn.cn/mod/assign/view.php?id=207974","http://xinjiang.ouchn.cn/mod/assign/view.php?id=207975S"));

        all.put("Dreamweaver网页设计", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=225457","http://xinjiang.ouchn.cn/mod/assign/view.php?id=225459","http://xinjiang.ouchn.cn/mod/assign/view.php?id=225460","http://xinjiang.ouchn.cn/mod/assign/view.php?id=225461","http://xinjiang.ouchn.cn/mod/assign/view.php?id=225463","http://xinjiang.ouchn.cn/mod/assign/view.php?id=225465","http://xinjiang.ouchn.cn/mod/assign/view.php?id=225457","http://xinjiang.ouchn.cn/mod/assign/view.php?id=225459","http://xinjiang.ouchn.cn/mod/assign/view.php?id=225460","http://xinjiang.ouchn.cn/mod/assign/view.php?id=225461","http://xinjiang.ouchn.cn/mod/assign/view.php?id=225463","http://xinjiang.ouchn.cn/mod/assign/view.php?id=225465"));
        all.put("国际公法", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=270726","http://xinjiang.ouchn.cn/mod/assign/view.php?id=270726"));
        all.put("西方经济学（本）", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=217694","http://xinjiang.ouchn.cn/mod/assign/view.php?id=217695","http://xinjiang.ouchn.cn/mod/assign/view.php?id=217697","http://xinjiang.ouchn.cn/mod/assign/view.php?id=217698","http://xinjiang.ouchn.cn/mod/assign/view.php?id=217694","http://xinjiang.ouchn.cn/mod/assign/view.php?id=217695","http://xinjiang.ouchn.cn/mod/assign/view.php?id=217697","http://xinjiang.ouchn.cn/mod/assign/view.php?id=217698"));
        all.put("人力资源管理", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=206657","http://xinjiang.ouchn.cn/mod/assign/view.php?id=206657"));
        all.put("数学思想与方法", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=198306","http://xinjiang.ouchn.cn/mod/assign/view.php?id=198307"));
        all.put("国际私法", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=270621","http://xinjiang.ouchn.cn/mod/assign/view.php?id=270621"));
        all.put("基础写作", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=260627","http://xinjiang.ouchn.cn/mod/assign/view.php?id=260627","http://xinjiang.ouchn.cn/mod/assign/view.php?id=260643","http://xinjiang.ouchn.cn/mod/assign/view.php?id=260643","http://xinjiang.ouchn.cn/mod/assign/view.php?id=260658","http://xinjiang.ouchn.cn/mod/assign/view.php?id=260658","http://xinjiang.ouchn.cn/mod/assign/view.php?id=260681","http://xinjiang.ouchn.cn/mod/assign/view.php?id=260681","http://xinjiang.ouchn.cn/mod/assign/view.php?id=260699","http://xinjiang.ouchn.cn/mod/assign/view.php?id=260709"));
        all.put("幼儿园课程与活动设计", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=343797"));
        all.put("建筑制图基础", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=237542","http://xinjiang.ouchn.cn/mod/assign/view.php?id=237542"));
        all.put("绩效与薪酬实务", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=206366","http://xinjiang.ouchn.cn/mod/assign/view.php?id=206368","http://xinjiang.ouchn.cn/mod/assign/view.php?id=206366","http://xinjiang.ouchn.cn/mod/assign/view.php?id=206368"));
        all.put("政治学原理", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=267793","http://xinjiang.ouchn.cn/mod/assign/view.php?id=267794","http://xinjiang.ouchn.cn/mod/assign/view.php?id=267796"));
        all.put("机械制图", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=231346","http://xinjiang.ouchn.cn/mod/assign/view.php?id=231347","http://xinjiang.ouchn.cn/mod/assign/view.php?id=231348","http://xinjiang.ouchn.cn/mod/assign/view.php?id=231349","http://xinjiang.ouchn.cn/mod/assign/view.php?id=231346","http://xinjiang.ouchn.cn/mod/assign/view.php?id=231347","http://xinjiang.ouchn.cn/mod/assign/view.php?id=231348","http://xinjiang.ouchn.cn/mod/assign/view.php?id=231349"));
        all.put("现代货币金融学说", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=210970","http://xinjiang.ouchn.cn/mod/assign/view.php?id=211142"));
        all.put("公司概论", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=323301","http://xinjiang.ouchn.cn/mod/assign/view.php?id=323372","http://xinjiang.ouchn.cn/mod/assign/view.php?id=323392"));
        all.put("微积分基础", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=289656","http://xinjiang.ouchn.cn/mod/assign/view.php?id=289657"));
        all.put("金融法规", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=318756","http://xinjiang.ouchn.cn/mod/assign/view.php?id=318795"));
        all.put("市场营销学", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=205216","http://xinjiang.ouchn.cn/mod/assign/view.php?id=205216"));
//   all.put("组织行为学", Lists.newArrayList(
//           "http://xinjiang.ouchn.cn/mod/assign/view.php?id=334393",
//           "http://xinjiang.ouchn.cn/mod/assign/view.php?id=334394",
//           "http://xinjiang.ouchn.cn/mod/assign/view.php?id=334395",
//           "http://xinjiang.ouchn.cn/mod/assign/view.php?id=334396",
//           "http://xinjiang.ouchn.cn/mod/quiz/view.php?id=206007",
//           "http://xinjiang.ouchn.cn/mod/quiz/view.php?id=206008",
//           "http://xinjiang.ouchn.cn/mod/quiz/view.php?id=206009",
//           "http://xinjiang.ouchn.cn/mod/quiz/view.php?id=206010"
//           ));
        all.put("阅读与写作(2)", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=290440"));
        all.put("软件工程", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=218921","http://xinjiang.ouchn.cn/mod/assign/view.php?id=218921"));
        all.put("公共部门人力资源管理", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=292808"));
        all.put("人员招聘与培训实务", Lists.newArrayList("http://xinjiang.ouchn.cn/mod/assign/view.php?id=206929","http://xinjiang.ouchn.cn/mod/assign/view.php?id=206929"));

        LinkedBlockingDeque<AnswerDTO> answerQueue = new LinkedBlockingDeque<>();

        // 获取所有的用户名和密码
        InputStream userInputStream = new FileInputStream("libs//allUser.txt");
        List<String> userString = IOUtils.readLines(userInputStream, "utf-8");
        Map<String, String> usernameAndPwd = Maps.newHashMap();
        for (String user : userString) {
            String[] strs = user.split(",");
            String userCode = strs[0];
            String pwd = strs[1].substring(6, 14);
            pwd = "Ouchn" + pwd;
            usernameAndPwd.put(userCode, pwd);
        }

        for(String subjectName:all.keySet()){
            //  LinkedList<AnswerRequestDTO> requestUrl = Lists.newLinkedList();
            LinkedList<String> requestUrl = Lists.newLinkedList(all.get(subjectName));

            log.info("subjectName:{}",subjectName);

            // 根据课程名称拿到 所有人 这里的用户只有用户名，没有密码
            List<String> userNames = DealInfoUtil.countUserCourseInfo("libs//userCourseInfo").get(subjectName);
            if(userNames == null){
                continue;
            }
            for(String username:userNames){
                if(!Util.getVip().contains(username)){
                    continue;
                }
                String pwd = usernameAndPwd.get(username);
                AnswerDTO answerDTO = new AnswerDTO();
                answerDTO.setSubjectName(subjectName);
                answerDTO.setUsername(username);
                answerDTO.setPwd(pwd);
                answerDTO.setCommit(true);
                answerDTO.setPush(false);
                answerDTO.setUploadUrl(requestUrl);
//                if(!answerDTO.getSubjectName().equals("行政领导学")){
//                    continue;
//                }
                answerQueue.add(answerDTO);
            }

        }

        for (int i = 1; i <= sync; i++) {
            Thread answerThread = new UploadFileTask(null,answerQueue);
            //log.info("加载课程ID：{} 名称：{} ", openCourseId,subjectName);
            answerThread.setName( "答题线程--" + i);
            answerThread.start();
        }


    }






}
